//
//  TestCenterInforVC.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/1/14.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "TestCenterInforVC.h"
#import <AVKit/AVKit.h>

@interface TestCenterInforVC ()
@property (strong, nonatomic) IBOutlet UIImageView *picture_img;
@property (strong, nonatomic) IBOutlet UILabel *title_lab;
@property (strong, nonatomic) IBOutlet UILabel *content_lab;
@property (strong, nonatomic) IBOutlet UIView *back_view;
@property (strong, nonatomic) IBOutlet UILabel *right_lab;


@end

@implementation TestCenterInforVC{
    RequestServices *service;
    NSDictionary *valueDic;//获取到的字典值
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"试验详情";
    self.title_lab.font = self.content_lab.font = self.right_lab.font = AutoLabFont2;
    
    service = [[RequestServices alloc]initWithDelegate:self];
    service.view = self.view;
    [service getTestCenterInfor:self.id tag:8000];  
}

#pragma mark - requestDelegate
-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    [self HideLoading];
    if (tag == 8000){
        valueDic = [NSDictionary dictionaryWithDictionary:obj];
        [self.picture_img sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",obj[@"cover"]]] placeholderImage:DefaultIcon];
        self.title_lab.text = [NSString stringWithFormat:@"试验名称：%@",obj[@"title"]];
         self.right_lab.text = [NSString stringWithFormat:@"%@",obj[@"detail"]];
        if ([obj[@"type"] intValue] == 1) {
            self.content_lab.text = [NSString stringWithFormat:@"试验类型：互动实验"];
        }
        if ([obj[@"type"] intValue] == 2) {
            self.content_lab.text = [NSString stringWithFormat:@"试验类型：模型展示"];
        }
        if ([obj[@"arPath"] CheckNSStringData]) {
            //ar路径返回有数据
             [self showVideo];
        }
//        if ([obj[@"cover"] CheckNSStringData]) {
//            //返回的图片有数据
//            UIImageView *img = [[UIImageView alloc]initWithFrame:self.back_view.bounds];
//            [img sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",obj[@"cover"]]]];
//            [self.back_view addSubview:img];
//        }
            
    }
}

-(void)getError:(NSError *)error tag:(long long)tag{
    [self HideLoading];
    [self ShowNewMsg:error.domain];
}


-(void)showVideo{
    
    //步骤1：获取视频路径
    NSString *webVideoPath = @"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
    NSURL *webVideoUrl = [NSURL URLWithString:webVideoPath];
    //步骤2：创建AVPlayer
    AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:webVideoUrl];
    //步骤3：使用AVPlayer创建AVPlayerViewController，并跳转播放界面
    AVPlayerViewController *avPlayerVC =[[AVPlayerViewController alloc] init];
    avPlayerVC.player = avPlayer;
    //步骤4：设置播放器视图大小
    avPlayerVC.view.frame = self.back_view.bounds;
    //特别注意:AVPlayerViewController不能作为局部变量被释放，否则无法播放成功
    //解决1.AVPlayerViewController作为属性
    //解决2:使用addChildViewController，AVPlayerViewController作为子视图控制器
    [self addChildViewController:avPlayerVC];
    
    [self.back_view addSubview:avPlayerVC.view];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
